package com.lxyk.service.impl;


import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.lxyk.mapper.HistoryMapper;
import com.lxyk.pojo.History;
import com.lxyk.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName HistoryServiceImpl
 * @Description TODO
 * @Author FJQ
 * @Date 2022/10/25 9:27
 * @Version 1.0
 **/
@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public List<History> listHistory() {
        return historyMapper.selectList(null);
    }

    @Override
    public List<History> queryHistory(Map<String, Object> map) {
        return historyMapper.listHistory(map);
    }

    @Override
    public PageInfo<History> listHistory(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        List<History> historyList = historyMapper.listHistory(map);
        return new PageInfo<>(historyList);
    }

    @Override
    public int addHistory(History history) {
        return historyMapper.saveHistory(history);
    }

    @Override
    public History getHistoryById(Integer hid) {
        return historyMapper.getHistoryById(hid);
    }

    @Override
    public int updateHistory(History history) {
        return historyMapper.updateHistory(history);
    }

    @Override
    public int batchDeleteHistory(String idList) {
        // 字符串转换为List集合
        String[] split = StrUtil.split(idList, ",");
        List<Integer> ids = new ArrayList<>();
        for (String id : split) {
            if (StrUtil.isNotEmpty(id)) {
                ids.add(Integer.parseInt(id));
            }
        }
        return historyMapper.batchDeleteHistory(ids);
    }
}
